<template>
    <div class="yd-ls-welcome-bg"></div>
</template>
<style>

</style>
<script>
import api from "../../../axios/api";
import { mapGetters } from "vuex";

export default {
  name: "welcome",
  data() {
    return {
      host_openid: {
        xfl: 'o8HFNwh9MjxfAd5e3CIVlKcm216g', //小肖
        lsc: 'o8HFNwjRIHPvkyVx058W5XAcDc2s', //我
      }
    }
  },
  computed: {
    ...mapGetters(["getToken"])
  },
  created() {
    let host = location.host
    let leh_server = host.indexOf('pay.6ewei.com')
    let local_server = host.indexOf('localhost:9527')
    if( leh_server === -1 &&  local_server === 0){
      localStorage.openId = this.host_openid.qyan_tst
      this.getAuthenticate()
    }else{
      
      if(!localStorage.openId) {
        // 获取openid
        this.getOpenid()
      }else {
        // 验证注册
        this.getAuthenticate()
      }
    }
    
  },
  methods: {
    init() {},
    getOpenid() {
      // 获取openid
      let _this = this;
      var src = window.location.search;
      var a = src.indexOf("code");
      var b = src.indexOf("&state");
      var code = src.substr(a + 5, b - (a + 5));

      this.axios({
        method: "get",
        url: api.wx_openid,
        params: {
          code: code,
          state: "STATE"
        },
        responseType: "text"
      })
        .then(rep => {
          localStorage.openId = rep.data;
          this.getAuthenticate();
        })
        .catch(err => {
          alert("OPENID_err" + JSON.stringify(err));
        });
    },
    getAuthenticate() {
      this.axios.get(api.get_authenticate).then(m => {
        this.$router.push("home");
      });
    }
  },
  mounted() {
    this.init();
  }
};
</script>
